<template>
	<view class="container">
		<view class="img">
			<image src="/static/images/chenggong.png" mode="widthFix"></image>
		</view>
		<view class="title">掃碼成功</view>
		<view class="btns">
			<u-button @click="confirm" class="custom-style" type="primary" text="確認"></u-button>
			<u-button @click="cancel" class="custom-style1" type="default" :hairline="true" :plain="true"
				text="取消"></u-button>
		</view>
	</view>
</template>

<script>
	import {
		setLoginStatus,
		changUserLoginType
	} from '@/api/index.js'

	export default {
		data() {
			return {
				details: '',
				equipmentID: '',
			};
		},
		onLoad(option) {
			// this.details = JSON.parse(option.details)
			// console.log(this.details,'1111111111')
			// console.log(option.details, '11111111111111')
			// console.log(option.equipmentID, '2222222222222222')

			this.equipmentID = option.equipmentID
			console.log(this.equipmentID,'設備嗎')
			setLoginStatus({
				equipmentID: option.equipmentID
			}).then(res => {
				console.log(res, '掃碼中...')
			})

		},
		methods: {
			cancel() {
				changUserLoginType({
					equipmentID: this.equipmentID,
					status: 2
				}).then(res => {
					console.log(res, '取消')
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
					setTimeout(() => {
						uni.reLaunch({
							url: '/pages/index/index'
						})
					}, 1500)
				})
			},
			confirm() {
				// console.log('確定')
				changUserLoginType({
					equipmentID: this.equipmentID,
					status: 1
				}).then(res => {
					console.log(res, '登陸')
					uni.showToast({
						title: '登入成功',
						icon: 'success'
					})
					setTimeout(() => {
						uni.reLaunch({
							url: '/pages/index/index'
						})
					}, 1500)
				})
			}
		}
	}
</script>

<style lang="less">
	.container {
		height: calc(100vh - 90rpx);
		background-color: #fff;
		padding: 30rpx;
		box-sizing: border-box;

		.img {
			margin: 100rpx auto 34rpx;
			width: 156rpx;
			// height: 115rpx;
			border-radius: 0rpx 0rpx 0rpx 0rpx;
			opacity: 1;

			// background-color: skyblue;
			image {
				width: 100%;
			}
		}

		.title {
			text-align: center;
			margin: 30rpx 0;
		}

		.btns {
			.custom-style {
				background-color: #39B19D;
				border: none;
				margin-bottom: 30rpx;
			}

			.custom-style1 {
				// background-color: skyblue;
				border: 1rpx solid #ccc;
			}
		}
	}
</style>